﻿CREATE PROCEDURE [dbo].[proc_Order_Item_Create]
	(
		@OId uniqueidentifier
		,@ProductId	int
		,@ProductName	nvarchar(50)
		,@UnitPrice	decimal(18, 2)
		,@Quantity	int
		,@Salesman	nvarchar(50)
		,@SalesmanAccount	nvarchar(50)
		,@DepId	int
		,@CompanyId	int
		,@CreateDate	datetime
		,@Occupancy	nvarchar(50)
		,@IsValid	bit	
		,@Description nvarchar(200)	
	)
AS
Begin
	If @SalesmanAccount Is Null Or @UnitPrice Is Null Or @Quantity Is Null
		Return

	Select @Salesman=EName,@DepId=DepartmentId,@CompanyId=CompanyId From Employee Where UserName=@SalesmanAccount
	If @DepId Is Null Or @CompanyId Is Null
		Return

	Insert into Order_Item
	(
		OId
		,ProductId
		,ProductName
		,UnitPrice
		,Quantity
		,Salesman
		,SalesmanAccount
		,DepId
		,CompanyId
		,CreateDate
		,Occupancy
		,IsValid
		,Description
	)
	Values
	(
		@OId
		,@ProductId
		,@ProductName
		,@UnitPrice
		,@Quantity
		,@Salesman
		,@SalesmanAccount
		,@DepId
		,@CompanyId
		,@CreateDate
		,@Occupancy
		,@IsValid
		,@Description
	)
End